﻿
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using KeRui.Common;
    using System.IO;

    /// <summary>
    /// WebSearch 的摘要说明
    /// </summary>
    public class WebSearchHelper
    {
        public string Domain = "";
        public string Site = "";
        public KeRui.BLL.CmsSite bllSite = new KeRui.BLL.CmsSite();
        public KeRui.Model.CmsSite modelSite = new KeRui.Model.CmsSite();

        public WebSearchHelper()
        {
            Domain = PageRequest.GetHost().ToLower();
            switch (Domain)
            {
                //宿迁
                case "jssq2010.iportalcms.cn":
                case "jssq.vnet.cn":
                    {
                        Site = "suqian";
                        break;
                    }
                //马鞍山
                case "www.mas.iportalcms.cn":
                case "www.mas.ah163.net":
                case "www.masrx.net":
                    {
                        Site = "maanshan";
                        break;
                    }
                //苏州
                case "test.iportalcms.cn":
                case "www0.iportalcms.cn":
                case "www.sz.iportalcms.cn":
                case "news.sz.iportalcms.cn":
                case "www.sz.js.cn":
                case "news.sz.js.cn":
                    {
                        Site = "suzhou";
                        break;
                    }
                //南通
                case "www.nt.iportalcms.cn":
                case "jsnt.vnet.cn":
                case "www.ntonline.cn":
                case "news.ntonline.cn":
                    {
                        Site = "nantong";
                        break;
                    }
                default:
                    break;
            }
        }

        /// <summary>
        /// 获得模块
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public string GetHtml(string module)
        {
            //debug 调试 liuliu
            //return FileObj.ReadFile(HttpContext.Current.Server.MapPath("/template/_websearch/" + Site + "/" + module.Replace(".", "/") + ".htm"));

            string html = "";
            if (Site == "")
                return html;

            string CacheKey = "WebSearchHelper-" + Site + "-" + module;
            object objModel = DataCache.GetCache(CacheKey);

            if (objModel == null)
            {
                try
                {
                    objModel = FileObj.ReadFile(HttpContext.Current.Server.MapPath("/template/_websearch/" + Site + "/" + module.Replace(".", "/") + ".htm"));
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("DataCache");
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            html = (string)objModel;

            return html;
        }

    }
